<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wwwApp: user/utils.php Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">wwwApp
   </div>
   <div id="projectbrief">A web app for workshop organizing, recruitment and qualification</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_111cd2f11cffd6d6d28d89ee0389ee9e.html">user</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">utils.php</div>  </div>
</div><!--header-->
<div class="contents">
<a href="user_2utils_8php.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * user/utils.php</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;</div>
<div class="line"><a name="l00010"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#ae6297fbd3e8fa7cc5feb6411a80deee9">   10</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#ae6297fbd3e8fa7cc5feb6411a80deee9">userIs</a>($role)</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;{</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;        global $USER;</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;        <span class="keywordflow">return</span> in_array($role, $USER[<span class="stringliteral">&#39;roles&#39;</span>]);</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;}</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#a1e9c8ed2c5ed2def1a367c9ffd04114b">   25</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#a1e9c8ed2c5ed2def1a367c9ffd04114b">userCan</a>($action, $owners=<span class="keyword">false</span>)</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;{</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        global $USER, <a class="code" href="common_8php.html#a7dc56dc8b18ad37272b56fa7395bedef">$DB</a>;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;        $roles = $USER[<span class="stringliteral">&#39;roles&#39;</span>];</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        <span class="keywordflow">if</span> ($owners === $USER[<span class="stringliteral">&#39;uid&#39;</span>] || (is_array($owners) &amp;&amp; in_array($USER[<span class="stringliteral">&#39;uid&#39;</span>], $owners)))</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;                <span class="keywordflow">if</span> (in_array(<span class="stringliteral">&#39;registered&#39;</span>, $USER[<span class="stringliteral">&#39;roles&#39;</span>]))</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;                        $roles[]= <span class="stringliteral">&#39;owner&#39;</span>;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        $required = $DB-&gt;query(<span class="stringliteral">&#39;SELECT role FROM table_role_permissions WHERE action=$1&#39;</span>, $action);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;        <span class="keywordflow">foreach</span> ($required as $requirements)</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;                <span class="keywordflow">if</span> (!count(array_diff(explode(<span class="charliteral">&#39; &#39;</span>, $requirements[<span class="stringliteral">&#39;role&#39;</span>]), $roles)))</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;                        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;}</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;</div>
<div class="line"><a name="l00043"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#a5bbc4a39c360e15b0c00714f18d2082b">   43</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#a5bbc4a39c360e15b0c00714f18d2082b">assertProfileFilled</a>($quiet = <span class="keyword">false</span>)</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;{</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        global $USER, <a class="code" href="common_8php.html#a7dc56dc8b18ad37272b56fa7395bedef">$DB</a>, <a class="code" href="index_8php.html#ae1848ae8dc4014bc7c680e5504a8eef0">$PAGE</a>;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        $user = $DB-&gt;users[$USER[<span class="stringliteral">&#39;uid&#39;</span>]]-&gt;assoc(<span class="stringliteral">&#39;school,graduationyear,interests&#39;</span>);</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <span class="keywordflow">if</span> (empty($user[<span class="stringliteral">&#39;graduationyear&#39;</span>]) || empty($user[<span class="stringliteral">&#39;school&#39;</span>]) || empty($user[<span class="stringliteral">&#39;interests&#39;</span>]))</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        {</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;                <span class="keywordflow">if</span> (!$quiet)</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;                        $PAGE-&gt;addMessage(_(<span class="stringliteral">&#39;Fill in &lt;a href=&quot;editProfile&quot;&gt;your profile&lt;/a&gt; first!&#39;</span>), <span class="stringliteral">&#39;userError&#39;</span>);</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;                <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        }</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;}</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#a94decde67d97df23a5959d489659b322">   57</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#a94decde67d97df23a5959d489659b322">gender</a>($m=<span class="charliteral">&#39;y&#39;</span>, $f=<span class="charliteral">&#39;a&#39;</span>, $gender=<span class="stringliteral">&#39;user&#39;</span>) <span class="comment">// TODO it&#39;s only used in genderize().</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;{</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        global $USER;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="keywordflow">if</span> ($gender === <span class="stringliteral">&#39;user&#39;</span>)</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;                $gender = $USER[<span class="stringliteral">&#39;gender&#39;</span>];</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;        <span class="keywordflow">return</span> (($gender === <span class="charliteral">&#39;f&#39;</span>) ? $f : $m);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;}</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#a7144fa5a413ad5690425b7b720aeedba">   74</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#a7144fa5a413ad5690425b7b720aeedba">genderize</a>($s, $gender=<span class="stringliteral">&#39;user&#39;</span>)</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;{</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        <span class="keywordflow">if</span> ($gender == <span class="charliteral">&#39;p&#39;</span>)</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;                <span class="keywordflow">return</span> str_replace(<span class="stringliteral">&#39;ł$a&#39;</span>, <span class="stringliteral">&#39;li&#39;</span>, str_replace(<span class="stringliteral">&#39;$y&#39;</span>, <span class="stringliteral">&#39;ych&#39;</span>, $s));</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        $s = str_replace(<span class="stringliteral">&#39;$ś&#39;</span>, <a class="code" href="user_2utils_8php.html#a94decde67d97df23a5959d489659b322">gender</a>(<span class="stringliteral">&#39;eś&#39;</span>,<span class="stringliteral">&#39;aś&#39;</span>,$gender), $s);</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        $s = str_replace(<span class="stringliteral">&#39;$y&#39;</span>, <a class="code" href="user_2utils_8php.html#a94decde67d97df23a5959d489659b322">gender</a>(<span class="charliteral">&#39;y&#39;</span>,<span class="charliteral">&#39;a&#39;</span>,$gender), $s);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        $s = str_replace(<span class="stringliteral">&#39;$a&#39;</span>, <a class="code" href="user_2utils_8php.html#a94decde67d97df23a5959d489659b322">gender</a>(<span class="stringliteral">&#39;&#39;</span>,<span class="charliteral">&#39;a&#39;</span>,$gender), $s);</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;        <span class="keywordflow">return</span> $s;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;}</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#a29f037f468ee2716970ae6e7293644e2">   90</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#a29f037f468ee2716970ae6e7293644e2">getUserBadge</a>($uid, $email=<span class="keyword">false</span>, $default=<span class="charliteral">&#39;?&#39;</span>)</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;{</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;        global $USER, <a class="code" href="common_8php.html#a7dc56dc8b18ad37272b56fa7395bedef">$DB</a>;</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="keywordflow">if</span> (!isset($DB-&gt;users[intval($uid)]))</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;                <span class="keywordflow">return</span> $default;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        $name = $DB-&gt;users[intval($uid)]-&gt;get(<span class="stringliteral">&#39;name&#39;</span>);</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        $icon = <span class="stringliteral">&#39;user-blue.gif&#39;</span>;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        <span class="keywordflow">if</span> ($uid == $USER[<span class="stringliteral">&#39;uid&#39;</span>])</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;                $icon = <span class="stringliteral">&#39;user-green.gif&#39;</span>;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="user_2utils_8php.html#a1e9c8ed2c5ed2def1a367c9ffd04114b">userCan</a>(<span class="stringliteral">&#39;editProfile&#39;</span>, $uid))</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;                $icon = <a class="code" href="template_8php.html#a4fbd311bbd72b7beba6f27fe63b0acb1">getIcon</a>($icon, _(<span class="stringliteral">&#39;edit profile&#39;</span>), <span class="stringliteral">&#39;editProfile(&#39;</span>. $uid .<span class="charliteral">&#39;)&#39;</span>);</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="keywordflow">else</span></div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;                $icon = <a class="code" href="template_8php.html#a4fbd311bbd72b7beba6f27fe63b0acb1">getIcon</a>($icon, _(<span class="stringliteral">&#39;profile on wikidot&#39;</span>), <span class="comment">// TODO profile on wikidot exists?</span></div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;                        <span class="stringliteral">&#39;http://warsztatywww.wikidot.com/&#39;</span>. urlencode($name));</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        $result = <span class="stringliteral">&quot;$icon $name&quot;</span>;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <span class="keywordflow">if</span> ($email)  $result .= <span class="stringliteral">&#39; &amp;lt;&#39;</span>. $DB-&gt;users[$uid]-&gt;get(<span class="stringliteral">&#39;email&#39;</span>) .<span class="stringliteral">&#39;&amp;gt;&#39;</span>;</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;}</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;</div>
<div class="line"><a name="l00117"></a><span class="lineno"><a class="code" href="user_2utils_8php.html#abfcbff4a35e363f8999bfa976125f491">  117</a></span>&#160;<span class="keyword">function</span> <a class="code" href="user_2utils_8php.html#abfcbff4a35e363f8999bfa976125f491">getUserRoles</a>($uid)</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;{</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        global <a class="code" href="common_8php.html#a7dc56dc8b18ad37272b56fa7395bedef">$DB</a>, $USER;</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;        $DB-&gt;query(<span class="stringliteral">&#39;SELECT role FROM table_user_roles WHERE uid=$1&#39;</span>, $uid);</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        $roles = $DB-&gt;fetch_column();</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        $r = $DB-&gt;query(<span class="stringliteral">&#39;SELECT lecturer, qualified FROM table_edition_users WHERE edition=$1 AND uid=$2&#39;</span>,</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;                <a class="code" href="utils_8php.html#a86acce3c002ca1af709fd1b04f2f82fa">getOption</a>(<span class="stringliteral">&#39;currentEdition&#39;</span>), $uid);</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        <span class="keywordflow">if</span> ($r-&gt;count())</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;        {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;                $status = $DB-&gt;fetch_assoc();</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;                $roles[]= ($status[<span class="stringliteral">&#39;lecturer&#39;</span>]) ? <span class="stringliteral">&#39;lecturer&#39;</span> : <span class="stringliteral">&#39;candidate&#39;</span>;</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;                <span class="keywordflow">if</span> ($status[<span class="stringliteral">&#39;qualified&#39;</span>])</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;                        $roles[]= <span class="stringliteral">&#39;qualified&#39;</span>;</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        }</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        <span class="keywordflow">return</span> $roles;</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;}</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sun Sep 8 2013 17:44:57 for wwwApp by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.1
</small></address>
</body>
</html>
